class Solution:
    def arrangeCoins(self, n: int) -> int:
        left, right = 1, n
        while left < right:
            mid = (left + right + 1) // 2
            num = mid * (mid + 1)
            if num <= 2 * n:
                left = mid
            else:  # num > 2 * n
                right = mid - 1
        return left


if __name__ == "__main__":
    print(Solution().arrangeCoins(5))  # 2
    print(Solution().arrangeCoins(8))  # 3
